﻿

$(document).ready(function () {

    // check user
    var _var = $("#CheckUser").val();
    if (_var != '40' && _var != null && _var != "") {
        $("#DVGTVT_MA").attr("disabled", "disabled");
    }
    $("input").bind("keydown", function (event) {
        // track enter key
        var keycode = (event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode));
        if (keycode == 13) { // keycode for enter key
            // force the 'Enter Key' to implicitly click the Update button
            document.getElementById('btnSearch').click();
            return false;
        } else {
            return true;
        }
    });


    $('.btn-file :file').on('fileselect', function (event, numFiles, label) {

        var input = $(this).parents('.input-group').find(':text'),
            log = numFiles > 1 ? numFiles + ' files selected' : label;

        if (input.length) {
            input.val(log);
        } else {
            if (log) alert(log);
        }

    });

    $("#DVGTVT_MA").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/GPS_HocVien/AutoCompleteDVGTVT_MA",
                type: "POST",
                dataType: "json",
                data: { term: request.term },
                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item.DVGTVT_TEN, value: item.DVGTVT_MA + ':' + item.DVGTVT_TEN };
                    }))
                }
            })
        },
        messages: {
            noResults: "", results: ""
        }
    }).click(function () {
        $(this).val("");
        $(this).autocomplete("search");
    });

    $("#KH_MA").autocomplete({
        source: function (request, response) {
            $.ajax({
                url: "/GPS_HocVien/AutoCompleteKH_MA",
                type: "POST",
                dataType: "json",
                data: { term: request.term },
                success: function (data) {
                    response($.map(data, function (item) {
                        return { label: item.KH_MA, value: item.KH_MA + ':' + item.KH_TEN };
                    }))
                }
            })
        },

    }).click(function () {
        var _val = $("#DVGTVT_MA").val();
        if (_val == null) {
            alert('Bạn phải nhập đơn vị đào tạo');
        }
        $(this).val("");
        $(this).autocomplete("search");
    });

});
